onload = function () {
	//获取单选框
	var rememberMe = document.getElementsByName("rememberMe")[0];
	//获取登录按钮
	var logging = document.getElementById("logging");

	//在Cookie中获取内容
	document.getElementById("username").value = getCookie("username");
	document.getElementById("password").value = getCookie("password");

	//点击登录事件
	logging.addEventListener("click", function () {
		//获取用户名与密码输入框
		var username = document.getElementById("username");
		var password = document.getElementById("password");
		//将用户名与密码上传到Cookie中
		if (rememberMe.checked) {
			setCookie("username", username.value, 7 * 24 * 3600);
			setCookie("password", password.value, 7 * 24 * 3600);
		}
	});

}
//expires的单位是秒
function setCookie ( key, value, expires, path){
	switch(arguments.length){
		case 0 :
		case 1 : throw new Error("传参错了，重输一次！！！");
		case 2 : {
			document.cookie = key + "=" + value;
			break;
		}
		case 3 : {
			var nam = arguments[2];
			if(typeof nam == "number"){
				var d = new Date();
				d.setSeconds(d.getSeconds()+nam);
				document.cookie = key + "=" + value +";expires=" + d;
			}else if(typeof nam == "string"){
				document.cookie = key + "=" + value +";path=" + nam;
			}
			break;
		}
		case 4 : {
			var d = new Date();
			d.setSeconds(d.getSeconds()+nam);
			document.cookie = key + "=" + value + ";expires=" + d +";path=" +path;
		}
	}
}

//
function getCookie(key) {
	var str = document.cookie;
	var list = str.split("; ");
	for(var i=0; i<list.length; i++) {
		var kvs = list[i].split("=");
		if(kvs[0] == key) {
			return kvs[1];
		}
	}

	return null;
}